package controllerLayer;
import modelLayer.*;


/**
 * Write a description of class DvdCTR here.
 * 
 * @author group 5 
 * @version 2014-11-04
 */
public class DvdCTR{
    private static DvdContainer dvdContainer = DvdContainer.getInstance();
    
    public void createDvd(int barcode, String title, String artist, String publicationDate){
        DVD d= new DVD (barcode, title, artist, publicationDate);
        dvdContainer.addDVD(d);
    }
    
     public void createCpy(String serialNumber, String purchaseDate, double purchasePrice, int barcode){
      DVD dvd = dvdContainer.getInstance().findDvdByBarcode(barcode);
        if(dvd!=null)
        {
         Copy c= new Copy (serialNumber, purchaseDate, purchasePrice);
        dvd.addCopy(c);
      }
     System.out.println("Enter a valid id");
     } 
    /**
     * This method updates Dvd's information.
     * If the field is blank you have to set the new parameter.
     * @param title
     * @param artist
     * @param publicationDate
     */
    public void updateDvd(DVD dvd,String title,String artist,String publicationDate)
    {
        if(!title.equals("-"))
        dvd.setTitle(title);
        if(!artist.equals("-"))
        dvd.setArtist(artist);
        if(!publicationDate.equals("-"))
        dvd.setPublicationDate(publicationDate);
    }
    /**
     * This method updates Copy's information.
     * If the field is blank you have to set the new parameter.
     * @param purchaseDate
     * @param purchasePrice
     */
    public void updateCpy(Copy cpy,String purchaseDate,double purchasePrice)
    {
        if(!purchaseDate.equals("-"))
        cpy.setPurchaseDate(purchaseDate);
        if(!Double.toString(purchasePrice).equals("-"))
        cpy.setPurchasePrice(purchasePrice);
    }
    
    public  DVD findDvd(int barcode){
        return dvdContainer.findDvdByBarcode(barcode);
    }
    
    public Copy findCpy(int barcode, String serialNumber) {
        return dvdContainer.getInstance().findDvdByBarcode(barcode).findCopyBySerial(serialNumber);
    }
    
    public void deleteDvd(DVD dvd){
        dvdContainer.deleteDVD(dvd);
    }
    
    public void deleteCpy(int barcode, String serialnumber){
        dvdContainer.getInstance().findDvdByBarcode(barcode).deleteCopy(serialnumber);
    } 
    
    public void printAllDvdss(){
        dvdContainer.getInstance().printAllDvds();
    }
    
    public void printDvdAndItsCopys(int barcode){
        if(findDvd(barcode)!=null)
        findDvd(barcode).showDvdAndItsCopys();
        {
            System.out.println("Enter a valid barcode");
        }
    }
    
}
